<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>修改餐厅</title>
<!--公共样式开始-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/reset.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/common.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/FontAwesome/css/font-awesome.min.css">
<!--公共样式结束-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/module_form.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/page_memberAdd.css">
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.min.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.timer.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/common.js"></script>
<script src="__PUBLIC__/Plugins/Datepicker/WdatePicker.js"></script>
</head>

<body>
	<div class="page_header">
		<div class="tabbar">
			<ul class="tab clearfix" tabname="tab1">
				<li class="tabhover" show="tab1_0">基本信息</li>
				<li show="tab1_1">详细信息</li>
			</ul>
		</div>
	</div>
	<div class="page_wraper">
	<form method="post" id="restaurantAdd_form">
		<div id="tab1_0" fortab="tab1">
			<table cellpadding="0" cellspacing="0" class="module_form" width="600">
			<input type="hidden" id="id" name="id" value="{$detail.id}">
			<fieldset>
				<tr>
					<td class="ele_title"><label for="cardnum">餐厅中文名称：<em>*</em></label></td>
					<td class="ele_content">
						<input name="title" value="{$detail.title}" type="text" id="title" class="form_ele_text width_200">
					</td>
					<td class="ele_title"><label for="cardnum">餐厅英文名称：<em>*</em></label></td>
					<td class="ele_content">
						<input name="entitle" value="{$detail.entitle}" type="text" id="entitle" class="form_ele_text width_200">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">订餐电话：<em>*</em></label></td>
					<td class="ele_content">
						<input name="tel" type="text" id="tel" value="{$detail.tel}" class="form_ele_text width_200">
					</td>
					<td class="ele_title"><label for="realname">营业时间：<em>*</em></label></td>
					<td class="ele_content">
						<input name="starthours" value="{$detail.starthours}" type="text" id="starthours" class="form_ele_text width_95 Wdate"
						onfocus="WdatePicker({skin:'whyGreen',dateFmt:'H:mm:ss'})"> -
						<input name="endhours" value="{$detail.endhours}" type="text" id="endhours" class="form_ele_text width_95 Wdate"
						onfocus="WdatePicker({skin:'whyGreen',dateFmt:'H:mm:ss'})">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">餐厅邮箱：</label></td>
					<td class="ele_content">
						<input name="email" value="{$detail.email}" type="text" id="email" class="form_ele_text width_200"></td>
					<td class="ele_title"><label for="sex">餐厅类型：</label></td>
					<td class="ele_content">
						<select class="width_200" name="type" id="type">
							<option value="">请选择</option>
							<option value="1" <eq name="detail.type" value="1">selected</eq>>直营店</option>
							<option value="2" <eq name="detail.type" value="2">selected</eq>>加盟店</option>
						</select>
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="iccard">餐厅星级：</label></td>
					<td class="ele_content" colspan="3">
						<select class="width_200" name="level" id="level">
							<option value="">请选择</option>
							<option value="1" <eq name="detail.level" value="1">selected</eq>>一星级</option>
							<option value="2" <eq name="detail.level" value="2">selected</eq>>二星级</option>
							<option value="3" <eq name="detail.level" value="3">selected</eq>>三星级</option>
							<option value="4" <eq name="detail.level" value="4">selected</eq>>四星级</option>
							<option value="5" <eq name="detail.level" value="5">selected</eq>>五星级</option>
						</select>
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="phone">餐厅菜系：</label></td>
					<td class="ele_content" colspan="3">
						<volist name="cuisine" id="v">
							<php>if(in_array($key,$cuisineArr)){</php>
								<input name="cuisine[]" type="checkbox" id="cuisine" value="{$key}" checked>{$v[0]}&nbsp;&nbsp;&nbsp;
							<php>}else{</php>
								<input name="cuisine[]" type="checkbox" id="cuisine" value="{$key}">{$v[0]}&nbsp;&nbsp;&nbsp;
							<php>}</php>
						</volist>
						
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="address1">所属地区：</label></td>
					<td colspan="3" class="ele_content">
						<div id="areaBox"></div>
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="d_input">餐厅地址：</label></td>
					<td colspan="3" class="ele_content">
						城市地址：<input type="text" value="{$detail.ssxadd}" class="form_ele_text  width_250" name="ssxadd" id="ssxadd" readonly>
							   <input type="hidden" value="{$detail.enssxadd}" class="form_ele_text  width_250" name="enssxadd" id="enssxadd" readonly>
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="d_input">&nbsp;</label></td>
					<td class="ele_content" colspan="3">
						详细地址：<input name="detail" value="{$detail.detail}" type="text" class="form_ele_text  width_300" id="address" placeholder="请输入中文详细地址">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="d_input">&nbsp;</label></td>
					<td class="ele_content" colspan="3">
						详细地址：<input name="endetail" value="{$detail.endetail}" type="text" class="form_ele_text  width_300" id="address" placeholder="请输入英文详细地址">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="d_input">标注信息点</label></td>
					<td class="ele_content" colspan="3">
						<input type="button" id="btn_lbs" data-toggle="modal" class="form_ele_submit" value="标注信息点" style="background-color:#39C">
						<input id="pointlat" name="latitude" value="{$detail.latitude}" type="text" class="form_ele_text  width_150" >
						<input id="pointlng" name="longitude" value="{$detail.longitude}" type="text" class="form_ele_text  width_150" >
					</td>
				</tr>
				</fieldset>
				<tr>
					<td colspan="4" class="print">
						<input name="" type="checkbox" value="">自动打印小票</td>
				</tr>
				<tr>
					<td colspan="4" style="height:30px;"></td>
				</tr>
			</table>
		</div>
		<div id="tab1_1" fortab="tab1" class="clearfix" style="display:none;">
			<table cellpadding="0" cellspacing="0" class="module_form" width="600">
				<tr>
					<td class="ele_title width_150"><label for="remark">简介（中文）：</label></td>
					<td class="ele_content">
						<textarea name="content" cols="" rows="" id="remark">{$detail.content}</textarea></td>
				</tr>
				<tr>
					<td class="ele_title width_150"><label for="remark">简介（英文）：</label></td>
					<td class="ele_content">
						<textarea name="encontent" cols="" rows="" id="remark">{$detail.encontent}</textarea></td>
				</tr>
				<tr>
					<td colspan="4" class="print">
						<input name="" type="checkbox" value="">自动打印小票</td>
				</tr>
				<tr>
					<td colspan="4" style="height:30px;"></td>
				</tr>
			</table>
		</div>
		</form>
	</div>
	<div class="page_footer pdtd10">
		<input type="button" name="submit" id="submit" value="提交数据"  class="form_ele_submit"/>
		<input type="reset" name="reset" id="reset" value="清空数据"  class="form_ele_reset"/>
	</div>
</body>
<script type="text/javascript">
	//弹出窗口全局变量
	var api = frameElement.api, W = api.opener;

	$(function(){
		//滑动门
		$('.tabbar li').click(function(){
			var tabname = $('.tabbar>ul').attr('tabname');
			$('.tabbar li').removeClass('tabhover');
			$(this).addClass('tabhover');
			
			$('div[fortab="'+tabname+'"]').hide();
			$('#'+$(this).attr('show')).show();
		});
		
		//表格隔行换色
		$('.module_form tr:odd').addClass('odd');
		$('.module_form tr:even').addClass('even');
		
		//表单操作
		//重置
		$('.form_ele_reset').on('click',function(){
			$('#memberAdd_form').get(0).reset();
		});
		
		$('#slef').change(function(){
			$("#vipno").val('');
			$("#vipno").attr("readonly",false);
		});
		
		$('#cardid').change(function(){
			if($("#slef").attr("checked")){
				
				var cardid = $("#cardid").val();
				
				if(cardid){
					$.post("{:U('Vipcard/getVipno')}",{'cardid':cardid},function(data){    //发异步请求会员卡号
						$("#vipno").val(data);
						$("#vipno").attr("readonly","readonly");
					});
				}
			}
		});
		
		//提交
		$('#submit').on('click',function(){
			//通过POST直接提交表单
			//$('#memberAdd_form').get(0).submit();
			//etcommon.maskShow();
			
			var tipsObj  = windowApi.lhgdialog.tips('正在提交数据...',5,etIcon.loading);
			var postData = $('#restaurantAdd_form').serialize();
			
			//通过Ajax提交表单
			postData += '&province='+$('#area2').val();
			postData += '&city='+$('#area3').val();
			postData += '&district='+$('#area4').val();
			
			$.post("{:U('Restaurant/edit')}", postData ,function(data){
					tipsObj.close();
					windowApi.lhgdialog.tips('数据提交成功！',1,etIcon.success,function(){
						frameApi.close(); //关闭当前窗口
						if(data.status==1){
							var obj = windowApi.lhgdialog.list['Restaurant_index'];
							obj.reload(obj);
						}else{
							windowApi.lhgdialog.alert(data.info,function(){return;});
						}
					});
				}, "json");
		});
		
		$('#btn_lbs').on('click',function(){
			var address = $('#ssxadd').val();
			var href    = "{:U('Restaurant/lbs_add')}&id={$detail['id']}";
			var width   = '600px';
			var height  = '420px';
			var title   = '标注信息点';
			openDialog('Restaurant_lbs_add',href,width,height,title);
		});
	});
	
	var linkage_json   = {$json|json_encode} ;
	var linkage_jsonen = {$jsonen|json_encode};
	$(function(){
		//初始值处理
		var did = '{$detail.area}';
		if(did!=''){
			var level = "{$row['level']}";
			$('#areaBox').html(dealInitialarea(did,'',level));
		}else{
			$('#areaBox').html(showLinkagearea(39,2,0));
		}
		$('select[name="area"]').live('change',function(){
			var nowLevel  = parseInt($(this).attr('level'));
			var nextLevel = nowLevel+1;
			var enhtml    = '';
			
			//清除自此以后的select
			$('select[name="area"]').each(function(index, element) {
				if(parseInt($(this).attr('level'))>nowLevel){
					$(this).remove();
				}
			});
			//给英文城市地址赋值
			$('select[name="area"]').each(function(index, element) {				
				var areaid = $(this).val();
				if(linkage_jsonen[areaid]){
					enhtml += linkage_jsonen[areaid][0];
				}
			});
			
			$('#ssxadd').val($('select[name="area"]').find("option:selected").text());
			$('#enssxadd').val(enhtml);
			
			$('input[name="area'+nowLevel+'"]').val($(this).val());
			//显示下一个select
			$('#areaBox').append(showLinkagearea($(this).val(),nextLevel,0));
		});
		
		//处理初始值
		function dealInitialarea(lid,result,level){
			if(lid){
				$.each(linkage_json , function(i, n){
					if(lid==i){
						result = dealInitialarea(n[1],result,(parseInt(level)-1))+''+showLinkagearea(n[1],level,i);
						return false;
					}
				});
			}
			return result;
		}
		
		//响应select改变事件
		function showLinkagearea(pid,level,nid){
			var html = ''; //最终输出的HTML
			var have = false; //是否有子词典
			html += '<select name="area" id="area'+level+'" level="'+level+'">';
			html += '<option value="0">请选择</option>';
			$.each(linkage_json , function(i, n){
				if(pid==n[1]){
					if(nid==i){
						html += '<option value="'+i+'" selected>'+n[0]+'</option>';
					}else{
						html += '<option value="'+i+'">'+n[0]+'</option>';
					}
					have = true;
				}
			});
			html += '</select>';
			html += '<input type="hidden" name="area'+level+'"/>';
			
			//没有子词典则此次输出为空
			if(!have){
				html = '';
			}
			return html;
		}
	});
</script>
</html>
